### Project 3 Playing Piano with Bananas **1.Introduction** ![](media/wps6.jpg) This project is similar to Project 2, just changing coins into bananas, to make the project close to daily life and fill with art. That is, change game into playing piano. In Project 2, we have imitated A, S, D, W, J, P keys. In this project, we will play piano with bananas. Find out an on-line piano software in your PC, and we can play a song through keys. But we simply imitate 6 keys. So we choose an easier song Song of Joy . In this song, we just need 6 keys, including J, K, L, I, H, E. **2.Song of Joy** J J K L L K J I H H I J J I IJ J K L L K J I H H I J I H H I I J H I J K J H I J K J I H I E J J K L L K J I H H I J I H H **3.Sample Code** ```c #include "UsbKeyboard.h" int InData1 = 0, InData2 = 0, InData3 = 0, InData4 = 0, InData5 = 0, InData0 = 0; //touch input value //temporary storage int TouchSensitivity = 20; //touch sensitivity. 0~1023,the larger the value, the lower the sensitivity. void setup() { for(int i = A0; i <= A5; i++) { pinMode(i, INPUT); //A0~A5 port as input port } for(int i = 6; i <= 12; i++) { pinMode(i, OUTPUT); //A0~A5 port as input port } TIMSK0 &= !(1 << TOIE0); } void loop() { UsbKeyboard.update(); //read out the voltage value of all pins, and because of pull-up resistor, //the default of all pins of maximum level is 1023,decrease the level of pins though touch. //so the value is by 1024-analogRead(A0); InData0 = 1024 - analogRead(A0); InData1 = 1024 - analogRead(A1); InData2 = 1024 - analogRead(A2); InData3 = 1024 - analogRead(A3); InData4 = 1024 - analogRead(A4); InData5 = 1024 - analogRead(A5); //trigger keyboard events with various possibility if(InData0 >= TouchSensitivity) { digitalWrite (11, HIGH); UsbKeyboard.sendKeyStroke(13); //J } else digitalWrite(11, LOW); if(InData1 >= TouchSensitivity) { digitalWrite(10, HIGH); UsbKeyboard.sendKeyStroke(14); //K } else digitalWrite(10, LOW); if(InData2 >= TouchSensitivity) { digitalWrite(9, HIGH); UsbKeyboard.sendKeyStroke(15); //L } else digitalWrite(9, LOW); if(InData3 >= TouchSensitivity) { digitalWrite(8, HIGH); UsbKeyboard.sendKeyStroke(12); //I } else digitalWrite(8, LOW); if(InData4 >= TouchSensitivity) { digitalWrite(7, HIGH); UsbKeyboard.sendKeyStroke(11);//H } else digitalWrite(7, LOW); if(InData5 >= TouchSensitivity) { digitalWrite(6, HIGH); UsbKeyboard.sendKeyStroke(8);//E } else digitalWrite(6, LOW); delay(100); } ``` **4.Result** After uploading program, take down one end of the Arduino cable on the control board; plug the end of the Arduino cable into Touch key USB Shield, and the other end still into PC USB port, now appearing new hardware “USB input device” on your PC. It is no need to install device driver, because generally XP and Win7 system support it. when one end connected to GND, hold the metal part of the other end of the alligator clip between your fingers with one hand; the other hand touches coins the other end of which have been connected to A1-A5 port . Now, you can play Song of Joy. **5.Code Explanation** Among above projects, we just change codes of A0-A5 to simulate various keys on keyboard. In fact, mainly set codes in UsbKeyboard.sendKeyStroke(XXXX). For example, in Project 3 , if we set A0 to simulate S Key, the code should be UsbKeyboard.sendKeyStroke(22); //S or UsbKeyboard.sendKeyStroke(KEY_S); //S. 22 corresponds to S Key, and we can find other keys corresponding to UsbKeyboard.h.